package com.hospital.workstation.controller;

import com.hospital.common.annotation.Log;
import com.hospital.common.annotation.RepeatSubmit;
import com.hospital.common.core.controller.BaseController;
import com.hospital.common.core.domain.R;
import com.hospital.common.core.validate.AddGroup;
import com.hospital.common.enums.BusinessType;
import com.hospital.workstation.domain.bo.FirstLevelBo;
import com.hospital.workstation.domain.bo.TwoLevelBo;
import com.hospital.workstation.domain.vo.TwoLevelVo;
import com.hospital.workstation.service.ITwoLevelService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 医学二级监护信息
 *
 * @author whb
 * @date 2023-04-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/workstation/twoLevel")
public class TwoLevelController extends BaseController {

    private final ITwoLevelService iTwoLevelService;

    /**
     * 获取医学二级监护信息详细信息
     *
     * @param medicalRecordNo 病历号
     * @return
     */
    @GetMapping("/{medicalRecordNo}")
    public R<TwoLevelVo> getInfo(@NotNull(message = "病历号不能为空") @PathVariable Integer medicalRecordNo) {
        return R.ok(iTwoLevelService.queryByMedicalRecordNo(medicalRecordNo));
    }

    /**
     * 新增或修改二级监护信息
     *
     * @param bo 二级监护业务对象
     * @return
     */
    @Log(title = "医学二级监护信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> addOrUpdate(@Validated(AddGroup.class) @RequestBody TwoLevelBo bo) {
        return toAjax(iTwoLevelService.insertOrUpdateByBo(bo));
    }
}
